<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>登录</title>

    <!-- Bootstrap core CSS -->
    <script src="https://cdn.jsdelivr.net/npm/jquery@1.12.4/dist/jquery.min.js"></script>
    <link href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">

    <!-- Custom styles for this template -->
    <!--<link href="signin.css" rel="stylesheet">-->
    <style type="text/css">
        body {
            padding-top: 140px;
            padding-bottom: 40px;
            background-color: #eee;
        }

        .form-signin {
            max-width: 330px;
            padding: 15px;
            margin: 0 auto;
        }

        .form-signin .form-signin-heading,
        .form-signin .checkbox {
            margin-bottom: 10px;
        }

        .form-signin .checkbox {
            font-weight: normal;
        }

        .form-signin .form-control {
            position: relative;
            height: auto;
            -webkit-box-sizing: border-box;
            -moz-box-sizing: border-box;
            box-sizing: border-box;
            padding: 10px;
            font-size: 16px;
        }

        .form-signin .form-control:focus {
            z-index: 2;
        }

        .form-signin input[type="email"] {
            margin-bottom: -1px;
            border-bottom-right-radius: 0;
            border-bottom-left-radius: 0;
        }

        .form-signin input[type="password"] {
            margin-bottom: 10px;
            border-top-left-radius: 0;
            border-top-right-radius: 0;
        }
    </style>

    <!--[if lt IE 9]>
    <script src="https://cdn.bootcss.com/html5shiv/3.7.3/html5shiv.min.js"></script>
    <script src="https://cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>

<body>

<div class="container">

    <form class="form-signin" method="post" th:action="@{/user/loginUser}" action="/user/loginUser">
        <h2 class="form-signin-heading" style="display: inline">请登录</h2>
        <a type="button" class="btn" th:href="@{/user/toRegisterPage}" style="margin-bottom: 5px;margin-left: 72px">没有账户,
            请注册</a>
        <br>
        <!--如果msg的值为空 不显示提示的信息-->
        <!--<span th:text="${msg}" th:if="${not #strings.isEmpty(msg)}" style="color: red"></span>-->
        <span id="message" th:text="${msg}" style="color: red"></span>
        <input type="text" id="username" name="username" class="form-control" maxlength="15" placeholder="请输入您的账户"
               onblur="usernameStatus()" required autofocus>
        <br>
        <input type="password" id="password" name="password" class="form-control" maxlength="15" placeholder="请输入您的密码"
               required>
        <div class="checkbox">
            <label>
                <input type="checkbox" value="remember-me"> 记住我
            </label>
            <a type="button" class="btn" th:href="@{/user/toUpdatePasswordPage}" style="margin-left: 150px">忘记密码</a>
        </div>
        <button class="btn btn-lg btn-primary btn-block" type="submit">登录</button>
    </form>

</div> <!-- /container -->
<script>
    function usernameStatus() {
        if ($("#username").val()!="") {
            $.ajax({
                type: "get",
                url: "/user/verityUser/" + $("#username").val(),
                success(data) {
                    if (data == "ERROR") {
                        console.log("控制台打印的信息=>>用户名" + $("#username").val() + "已存在");
                        //$("#message").text("用户名" + $("#username").val() + "存在可用，但不知道是否已激活");
                        $.ajax({
                            type: "get",
                            url: "/user/usernameStatus/" + $("#username").val(),
                            success(data) {
                                if (data == 1) {
                                    console.log("控制台打印的信息=>>用户已激活");
                                    // $("#message").text("状态码是1");
                                    $("#username").css("color", "green");
                                } else if (data == 0) {
                                    console.log("控制台打印的信息=>>用户未激活");
                                    // $("#message").text("状态码是0");
                                    $("#username").css("color", "red");
                                }
                            },
                            error() {
                                $("#message").text("");
                                $("#username").css("color", "black");
                                console.log("ajax配置有错，请检查url与type是否正确");
                            }
                        });
                    } else {
                        // 这里应该不做反应，或是与if进行反向操作
                        $("#message").text("");
                        $("#username").css("color", "black");
                    }
                },
                error() {
                    console.log("ajax配置有错，请检查url与type是否正确");
                }
            });
        }
    }
</script>
</body>
</html>





